package cn.hdu.liang.core.service.country;

import cn.hdu.liang.core.bean.country.City;
import cn.hdu.liang.core.dao.country.CityDao;
import cn.hdu.liang.core.query.country.CityQuery;
import cn.itcast.common.page.Pagination;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 市
 */
@Service
@Transactional
public class CityServiceImpl implements CityService {

    @Resource
    CityDao cityDao;

    public Integer addCity(City city) {
        return cityDao.addCity(city);
    }

    @Transactional(readOnly = true)
    public City getCityByKey(Integer id) {
        return cityDao.getCityByKey(id);
    }

    @Transactional(readOnly = true)
    public List<City> getCitysByKeys(List<Integer> idList) {
        return cityDao.getCitysByKeys(idList);
    }

    public Integer deleteByKey(Integer id) {
        return cityDao.deleteByKey(id);
    }

    public Integer deleteByKeys(List<Integer> idList) {
        return cityDao.deleteByKeys(idList);
    }

    public Integer updateCityByKey(City city) {
        return cityDao.updateCityByKey(city);
    }

    @Transactional(readOnly = true)
    public Pagination getCityListWithPage(CityQuery cityQuery) {
        Pagination p = new Pagination(cityQuery.getPageNo(), cityQuery.getPageSize(), cityDao.getCityListCount(cityQuery));
        p.setList(cityDao.getCityListWithPage(cityQuery));
        return p;
    }

    @Transactional(readOnly = true)
    public List<City> getCityList(CityQuery cityQuery) {
        return cityDao.getCityList(cityQuery);
    }
}
